#include<iostream>
#include<functional>
#include<memory>
#include"Log.hpp"
#include"TcpServer.hpp"// 处理IO
#include"Calculator.hpp"// 处理业务

Calculator calculator;

void DefaultOnMessage(std::weak_ptr<Connection> conn){
    if(conn.expired()) return;
    auto connection_ptr = conn.lock();
    // //对报文进行处理，有bug
    std::cout<<"上层得到了数据: "<<connection_ptr->Inbuffer()<<std::endl;
    std::string response_str = calculator.Handler(connection_ptr->Inbuffer());
    if(response_str.empty()) return;
    lg(Debug, "%s",response_str.c_str());
    connection_ptr->AppendOutBuffer(response_str);

    auto tcpserver = connection_ptr->_tcp_server_ptr.lock();
    tcpserver->Sender(connection_ptr);
}

int main(){
    Connection c1(1234);
    
    std::shared_ptr<TcpServer> epoll_svr(new TcpServer(8888,DefaultOnMessage));
    epoll_svr->Init();
    epoll_svr->Loop();
    return 0;
}